package cn.lds.springbootmybatisplusexamplej380.dto;

public class ResponseDTO<T> {

    private Integer code;
    private String msg;
    private T data;

    public ResponseDTO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    @Override
    public String toString() {
        return "ResponseDTO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static ResponseDTO buildSuccess(){
        return new ResponseDTO(ResponseEnum.SUCCESS.code,ResponseEnum.SUCCESS.msg,null);
    }

    public static ResponseDTO buildSuccess(Object o){
        return new ResponseDTO(ResponseEnum.SUCCESS.code,ResponseEnum.SUCCESS.msg,o);
    }

    public static ResponseDTO buildError(String msg){
        return new ResponseDTO(ResponseEnum.ERROR.code, msg,null);
    }




}
